package org.springblade.oa.feign;

import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.oa.service.IStatisticsService;
import org.springblade.system.entity.Dict;
import org.springblade.system.feign.IDictClient;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@ApiIgnore
@RestController
@AllArgsConstructor
public class StatisticsClient implements IStatisticsClient{
	IDictClient dictClient;
	private IStatisticsService statisticsService;

	@Override
	public R<Map<String,String>> getCostByProjectId(String projectCode) {

		HashMap<String, Object> params= new HashMap<>();
		params.put("xmid",projectCode);
		//差旅金额
		List<Map<String, Object>> list = statisticsService.getCLdata(params);
		String clSum="0.00";
		if (list != null && list.size() > 0) {
			clSum = list.get(0).get("je").toString();
		}
		List<Dict> costType = dictClient.getList("bx_costtype").getData();
		Double tjSum=0.00;//团建总金额
		Double otherSum=0.00;//其他
		for (int i = 0; i < costType.size(); i++) {
			params.put("costType",costType.get(i).getDictKey());
			List<Map<String, Object>> lx = statisticsService.getfyData(params);
			if (costType.get(i).getDictKey()==3){
				if (lx.get(0) != null && lx.get(0).size() > 0) {
					tjSum=tjSum+Double.parseDouble(lx.get(0).get("je").toString());
				}
			}else{
				if (lx.get(0) != null && lx.get(0).size() > 0) {
					otherSum=otherSum+Double.parseDouble(lx.get(0).get("je").toString());
				}
			}
		}
		Map<String, String> fyMap = new HashMap<>();
		fyMap.put("cl",clSum);
		fyMap.put("tj",tjSum.toString());
		fyMap.put("other",otherSum.toString());
		return R.data(fyMap);
	}
}
